package dwarffortress.tools;

import dwarffortress.data.DFEntity;
import dwarffortress.analysis.StructureAnalyzer;
import dwarffortress.annotations.SameLengthAsPrevious;
import dwarffortress.annotations.FixedValue;

public class StructureDumper {
    public static void main(String[] args) {
        StructureAnalyzer analyzer = new StructureAnalyzer(DFEntity.class);
        System.out.printf("|| *Index* || *Type* || *Field name*  || *Notes* || %n");

        for (int i = 0; i < analyzer.getFieldCount(); i++) {
            String notes = "";
            if (analyzer.isArray(i)) {
                if (null != analyzer.getField(i).getAnnotation(SameLengthAsPrevious.class)) {
                    notes += "Same length as previous array. ";
                }
            }
            if (!analyzer.isArray(i)) {
                if (null != analyzer.getField(i).getAnnotation(FixedValue.class)) {
                    FixedValue value = analyzer.getField(i).getAnnotation(FixedValue.class);
                    if (value.essential()) {
                        notes += String.format("Only observed value is %d. Some data may follow in other cases. ", value.value());
                    } else {
                        notes += String.format("Only observed value is %d. ", value.value());
                    }
                }
            }
            System.out.printf("|| %3d || %25s || %s  || %s ||%n", i, analyzer.getFieldTypeDescription(i), analyzer.getField(i).getName().substring(5), notes);
        }


    }
}
